package com.fresh.util;

import com.fresh.entity.FreshCategory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 遍历工具类
 */
@Component
@Scope("prototype")
public class RecursionUtil {

    private List<Integer> ids = new ArrayList<>();

    /**
     * 无限遍历FreshCategory树形结构
     * @param categoryList
     * @return
     */
    public List<Integer> getIds(List<FreshCategory> categoryList){
        for (FreshCategory category : categoryList) {
            ids.add(category.getId());
            if (category.getCategories() != null){
                getIds(category.getCategories());
            }
        }
        return ids;
    }
}
